home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 2
/
Nebula Two.iso
/
SourceCode
/
AlexNeXTSTEPSource
/
Source
/
Chapter8_Prefs
/
PopUp
/
PopUp_main.m
< prev
next >
Wrap
Text File
|
1995-06-12
|
2KB
|
89 lines
#import <appkit/appkit.h>
#import "TargetObject.h"
// a minimal program to demonstrate how
// to use a popuplist
main()
{
// create an application object
// to establish connection to
// Window Server
id NXApp = [Application new];
id theWindow;
id theMenu;
id theButton;
NXRect theRect;
id thePopUpList;
id theTargetObject;
id menuCell;
// create a window that's at 125, 125
// and is 200 by 300 pixels
NXSetRect(&theRect, 125, 125, 200, 300);
theWindow = [ [Window alloc]
initContent:&theRect
style: NX_TITLEDSTYLE
backing:NX_BUFFERED
buttonMask:NX_MINIATURIZEBUTTONMASK
defer:YES];
// create the menu
theMenu = [ [Menu alloc]
initTitle: [NXApp appName]];
// create the menu option
[theMenu addItem:"Quit"
action:@selector(terminate:)
keyEquivalent:'q'];
// resize menu to accomodate menu option
[theMenu sizeToFit];
[NXApp setMainMenu:theMenu];
// create a button that's 80 x 20
NXSetRect(&theRect, 0, 0, 80, 20);
theButton = [ [Button alloc]
initFrame:&theRect];
// set the title for the button
[theButton setTitle:"Press Here"];
// since the button is a view, we need
// to install it as the subview of the
// window's contentview or else it
// won't draw
[ [theWindow contentView]
addSubview: theButton];
// create the target of the popuplist
theTargetObject =
[[TargetObject alloc] init];
// create the popuplist
thePopUpList = [[PopUpList alloc] init];
// add items to the popup list
// and set each tag
// addItem: returns the added menucell
menuCell = [thePopUpList addItem:"Item 1"];
[menuCell setTag:1];
menuCell = [thePopUpList addItem:"Item 2"];
[menuCell setTag:2];
menuCell = [thePopUpList addItem:"Item 3"];
[menuCell setTag:3];
// set the target and action for
// the popup list
[thePopUpList setTarget:theTargetObject];
[thePopUpList
setAction:@selector(printSelection:)];
// attach button to popuplist
NXAttachPopUpList(theButton,
thePopUpList);
// send the window to the front
// and display it
[theWindow makeKeyAndOrderFront:nil];
// go into event loop to wait for events
[NXApp run];
}